#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
int a[N], tmp[N];
bool flag[N];
int mx;
void solve(int n, int m) {
    if (m == n) {
        int sum = 0;
        for (int i = 1; i <= n; ++i) {
            int c = 0;
            for (int j = i-1; j > 0; --j) {
                if (flag[i] == flag[j]) {
                    if (a[i] == a[j]) c = a[j];
                    break;
                }
            }
            sum += c;
        }
        mx = max(mx, sum);
        return ;
    }
    flag[++m] = true;
    solve(n, m);
    flag[m] = false;
    solve(n, m);
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while (T--) {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i)
            scanf("%d", a + i), tmp[i] = a[i];
        sort(tmp + 1, tmp + n + 1);
        bool tmpflag = true;
        for (int i = 1; i <= n; ++i) {
            if (tmp[i] == tmp[i-1]) {
                tmpflag = false;
                break;
            }
        }
        if (tmpflag) {
            puts("0");
            continue;
        }
        if (n <= 23) solve(n, 0);
        else {
            for (int i = 1; i <= n; ++i)
                if (tmp[i] == tmp[i-1]) ++mx;
        }
        printf("%d\n", mx);
        mx = 0;
    }

}
